import {
  SAVE_ALL_THRESHOLD,
  SAVE_ANALYSIS_WELLS,
  SAVE_BASE_LINE,
  SAVE_BASELINE_TYPE,
  SAVE_CQ_SINGLE_THRESHOLD,
  SAVE_DATA_ANALYSIS_METHOD,
  SAVE_GROUP_BY_LISTS,
  SAVE_HEAT_MAP_INFO,
  SAVE_MESSAGE_LISTS,
  SAVE_QUANTIFICATION_CUT_OFF,
  SAVE_TABLE_SELECTED_LISTS,
  SAVE_TARGET_SELECTED_ARR,
  SVAE_SIGLEVEL,
  SVAE_ISTARGET
} from "./constants";
import storageSession from "redux-persist/lib/storage/session";
import {persistReducer} from "redux-persist";
import {DATA_ANALYSIS_METHOD_1, GROUP_BY_LISTS, HEAT_MAP_TYPE_CQ, TABLE_SELECTED_LISTS} from "../config";
import {THRESHOLD} from "../../../../store/constants";
import {DATA_ANALYSIS_METHOD_2} from "../../../../calculation/components/quantification/config";


const persistConfig = {
  key: "user",
  storage: storageSession,
  whitelist: [""] //  白名单:runStart会存入缓存，其他不会存
};

const defaultState = {
  targetSelectedArr: [],
  reduxMessageLists: [],
  dataAnalysisMethod: DATA_ANALYSIS_METHOD_2,
  tableSelectedLists: TABLE_SELECTED_LISTS,
  allThreshold: "",
  analysisWells: [],
  groupByLists: GROUP_BY_LISTS,
  baseLine: {
    startCycle: 3,
    endCycle: 15
  },
  heatMapInfo: {
    target: "",
    type: HEAT_MAP_TYPE_CQ
  },
  baselineType: "auto",
  cqSingleThreshold: THRESHOLD,
  quantificationCutOff: {left: 300, right: 700},
  sigLevel: 5,
  isTarget:true
};

function reducer(state = defaultState, action) {
  switch (action.type) {
    case SAVE_TARGET_SELECTED_ARR :
      return {...state, targetSelectedArr: action.targetSelectedArr};
    case SAVE_MESSAGE_LISTS :
      return {...state, reduxMessageLists: action.reduxMessageLists};
    case SAVE_DATA_ANALYSIS_METHOD :
      return {...state, dataAnalysisMethod: action.dataAnalysisMethod};
    case SAVE_TABLE_SELECTED_LISTS :
      return {...state, tableSelectedLists: action.tableSelectedLists};
    case SAVE_ALL_THRESHOLD :
      return {...state, allThreshold: action.allThreshold};
    case SAVE_ANALYSIS_WELLS :
      return {...state, analysisWells: action.analysisWells};
    case SAVE_GROUP_BY_LISTS :
      return {...state, groupByLists: action.groupByLists};
    case SAVE_BASE_LINE :
      return {...state, baseLine: action.baseLine};
    case SAVE_HEAT_MAP_INFO :
      return {...state, heatMapInfo: action.heatMapInfo};
    case SAVE_BASELINE_TYPE :
      return {...state, baselineType: action.baselineType};
    case SAVE_CQ_SINGLE_THRESHOLD :
      return {...state, cqSingleThreshold: action.cqSingleThreshold};
    case SAVE_QUANTIFICATION_CUT_OFF :
      return {...state, quantificationCutOff: action.quantificationCutOff};
    case SVAE_SIGLEVEL :
      return {...state, sigLevel: action.sigLevel};
      case SVAE_ISTARGET :
      return {...state, isTarget: action.isTarget};
    default:
      return state;
  }
}

export default persistReducer(persistConfig, reducer);
